<template>
  <div class="orderContainer">
    <div class="titleBox">
      <div class="title">
        我的订单
      </div>
    </div>
    <div class="orderBox">
      <div class="header">
        <div
          v-for="(item, index) in statuList"
          :key="item.status"
          class="title"
          :class="{ active: tabIndex == index }"
          @click="selectedIndex(item, index)"
        >
          {{ item.title }}
          <div
            v-if="item.nums != undefined&&item.nums!=0"
            class="nums"
          >
            {{ item.nums }}
          </div>
        </div>
      </div>
      <div class="searchBox">
        <div class="searchInfo">
          <el-form
            :inline="true"
            :model="formInline"
            :label-position="labelPosition"
            label-width="80px"
            class="demo-form-inline"
          >
            <div>
              <el-form-item label="订单编号">
                <el-input
                  v-model="formInline.searchOrderNo"
                  placeholder="输入订单编号查询"
                  class="selectAddress"
                  style="width: 19.38rem"
                />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="商品名">
                <el-input
                  v-model="formInline.searchGoodsName"
                  placeholder="输入商品名查询"
                  class="selectAddress"
                  style="width: 19.38rem"
                />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="成交日期">
                <el-date-picker
                  v-model="formInline.searchTimer"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="-"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  style="width: 19.38rem"
                  :picker-options="pickerOptions"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </div>
            <div>
              <el-form-item label="收货人">
                <el-input
                  v-model="formInline.searchReviceName"
                  placeholder="输入收货人查询"
                  class="selectAddress"
                  style="width: 19.38rem"
                />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div
          class="searchBtn"
          @click="SearchClick"
        >
          搜索
        </div>
      </div>
    </div>
    <orderList
      ref="Search"
      :status="status"
      @goDetail="goDetail"
      @delOrder="delOrder"
    />
    <!-- <PageNation /> -->
  </div>
</template>

<script>
	import orderList from "../../components/order/list.vue";
	// import PageNation from "../../components/common/page_nation.vue";
	export default {
		components: {
			orderList,
			// PageNation,
		},
		data() {
			return {
				// 订单状态 
				// SUBMITORDER(“提交订单”,”待提交”,0) 
				// PAYMONEY(“订单付款”,”待付款”,1) 
				// DELIVERGOODS(“订单发货”,”待发货”,2) 
				// TAKEDELIVERY(“订单收货”,”待收货”,3) 
				// ENDORDER(“订单完成”,”已完成”,4) 
				// SALERETURN(“退货”,”退货”,5) 
				// CLOSEORDER(“订单关闭”, “已关闭”, 6) 
				// HASSEPERATE(“已拆分”, “已拆分” ,7) 
				// DEPOSITPAY(“定金付款”,”待付定金”, 8) 
				// UNREMARK(“待评价”,”待评价”, 9)
				statuList: [{
						status: 0,
						title: "全部订单",
						statusName: "",
					},
					{
						status: 1,
						title: "待付款",
						nums: 0,
						statusName: "PAYMONEY",
					},
					{
						status: 2,
						title: "待发货",
						nums: 0,
						statusName: "DELIVERGOODS",
					},
					{
						status: 3,
						title: "待收货",
						nums: 0,
						statusName: "TAKEDELIVERY",
					},
					{
						status: 4,
						title: "待评价",
						nums: 0,
						statusName: "UNREMARK",
					},
				],
				dataList: [{}, {}, {}, {}, {}],
				tabIndex: 0,
				status: "",
				labelPosition: "right",
				formInline: {
					searchOrderNo: "", // 通过订单号查询
					searchGoodsName: "", // 商品名
					searchTimer: [], // 成交日期
					searchReviceName: "", // 收货人
				},
				pageIndex: 1,
				pageSize: 10,
				pickerOptions: {
					shortcuts: [{
							text: "最近一周",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近一个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近三个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
								picker.$emit("pick", [start, end]);
							},
						},
					],
				},
				timer: "",
				payMoney: 0,
			};
		},
		mounted() {
			this.getOrderStyleCount();
		},
		methods: {
			//订单删除成功
			delOrder(status) {
				if (status) {
					this.getOrderStyleCount();
				}
			},
			//选择状态
			selectedIndex(item, index) {
				this.status = item.statusName;
				this.tabIndex = index;
				this.formInline = {
					searchOrderNo: "", // 通过订单号查询
					searchGoodsName: "", // 商品名
					searchTimer: [], // 成交日期
					searchReviceName: "", // 收货人
				}
			},
			//跳转详情
			goDetail() {
				this.$router.push({
					path: "/person/orderDetail",
					params: {
						goods: 1,
					},
				});
			},
			// 搜索
			SearchClick() {
				console.log('搜索', this.formInline)
				this.$refs.Search.SearchObj(this.formInline)

			},
			//获取各状态订单数量
			getOrderStyleCount() {
				let params = {
					token: localStorage.getItem("token"),
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
				};

				this.$api.person.getOrderStyleCount(params).then((res) => {
					if (res.code == 200) {
						console.log('获取各状态订单数量', res.data);
						let obj = [];
						res.data.forEach((item, index) => {
							console.log(item, index);
							if (index > 0) {
								let objs = {
									key: item[0],
									val: item[1],
								};
								obj.push(objs);
							}
						});
						console.log(obj);
						this.statuList.forEach((item) => {
							obj.forEach((items) => {
								if (item.statusName == items.key) {
									this.$set(item, "nums", items.val);
								}
							});
						});
						let total = 0
						this.statuList.forEach((item) => {
							if(item.status != 0){
								total += item.nums
							}
						});
						this.statuList.forEach((item) => {
							if(item.status == 0){
								this.$set(item, "nums", total);
							}
						});
						console.log('1111', this.statuList);
					}
				});
			},
		},
	};
</script>

<style scoped lang="scss">
	.orderContainer {
		.titleBox {
			display: flex;
			flex-direction: row;
			padding: 2.75rem 2.63rem 0 2.63rem;
			align-items: center;
			background: #fff;

			.title {
				font-size: 1.13rem;
				color: #333;
			}
		}

		.orderBox {
			background-color: #fff;
			padding: 1.31rem 1.75rem 0;

			.header {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				border-bottom: 0.06rem solid rgba(216, 216, 216, 1);

				.title {
					cursor: pointer;
					font-size: 1.25rem;
					padding: 0.63rem 0.94rem;
					position: relative;

					.nums {
						position: absolute;
						right: -0.5rem;
						top: 0;
						width: 1.38rem;
						height: 1.38rem;
						text-align: center;
						line-height: 1.38rem;
						background: #f0406f;
						border-radius: 50%;
						color: #fff;
						font-size: 0.75rem;
					}

					&.active {
						color: #f0406f;
						position: relative;
						padding: 0.63rem 0.94rem;
						border-bottom: 0.31rem solid rgba(240, 64, 111, 1);
					}
				}
			}

			.searchBox {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding: 1.63rem 0 0;
				align-items: flex-start;

				.searchInfo {
					.el-form {
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;

						>div {

							&:nth-child(2n) {
								margin-right: 0;
							}
						}
					}
				}

				.searchBtn {
					width: 3.69rem;
					font-size: 0.88rem;
					padding: 0.7rem;
					color: #fff;
					text-align: center;
					background: rgba(0, 0, 0, 1);
					border: 0px solid rgba(0, 0, 0, 1);
					border-radius: 0.2rem;
					cursor: pointer;

					&:hover {
						opacity: 0.7;
					}
				}
			}
		}
	}
</style>
